package GUI;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JScrollPane;
import javax.swing.JEditorPane;
import javax.swing.JTextPane;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.BoxLayout;
import javax.swing.JTextArea;
import javax.swing.JLabel;
import java.awt.Choice;
import java.awt.Label;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Button;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFormattedTextField;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Color;
import javax.swing.JTabbedPane;
import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.border.MatteBorder;
import java.awt.ItemSelectable;
import java.util.Vector;


import start.ClientConsole;

public class Gui_Student_Entry_Window extends JPanel{
	private JTextField txtWelcomeStudent;
	private JTextField txtPleaseChooseOne;
	public JButton btnNewButton ;
	ClientConsole m_chat;
	String m_UserID;
	/**
	 * 
	 */
	
	public void ExitProg()
	{
		System.exit(0);
	}
	public Gui_Student_Entry_Window() {
		
		setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
		setForeground(Color.GREEN);
		setLayout(null);
		
		
		
		txtWelcomeStudent = new JTextField();
		txtWelcomeStudent.setBackground(Color.LIGHT_GRAY);
		txtWelcomeStudent.setLocation(220, 11);
		txtWelcomeStudent.setText("Welcome -= Student name =- \r\n");
		txtWelcomeStudent.setSize(155, 20);
		add(txtWelcomeStudent);
		
		txtPleaseChooseOne = new JTextField();
		txtPleaseChooseOne.setFont(new Font("Tahoma", Font.PLAIN, 16));
		txtPleaseChooseOne.setBackground(Color.LIGHT_GRAY);
		txtPleaseChooseOne.setText("Please choose one of \r\nthe following options:");
		txtPleaseChooseOne.setBounds(10, 78, 328, 80);
		add(txtPleaseChooseOne);
		txtPleaseChooseOne.setColumns(10);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(10, 203, 576, 366);
		add(tabbedPane);
		
		JComboBox comboBox = new JComboBox();
		comboBox.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				JComboBox cb = (JComboBox)e.getSource();
		        String petName = (String)cb.getSelectedItem();
		        if(petName.equalsIgnoreCase("Student Information"))
		        {	// StudentsID,FirstName,SecondName,Address,DateOfBirth
		        	String LoginQuery = new String("select * from students s where s.StudentsID="+m_UserID);
		        	m_chat.client.flag=0; // Reset msg receive flag to null
		        	m_chat.SendMsg(LoginQuery); // Send Query

		    		while(0 == m_chat.client.flag)
		    		{
		    		}
		    		
		    		if (m_chat.client.MsgFromServer instanceof Vector)
		    		{
		    			Vector<String[]> result=(Vector<String[]>)m_chat.client.MsgFromServer;
		    			if(0 == m_chat.client.flag)
		    			{
		    				System.out.println("\n-===== TEST =====-");
		    			}
		    		}
		        }


			}
		});
		comboBox.setBackground(Color.LIGHT_GRAY);
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"", "Student Information", "Submit Assignment"}));
		comboBox.setBounds(370, 110, 140, 28);
		add(comboBox);
		
		btnNewButton = new JButton("Log off");
		
		btnNewButton.setBounds(451, 587, 105, 37);
		add(btnNewButton);
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);											
			}});
		this.setVisible(true);
	}
}
